﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace DLL.TrainingPerson
{
	/// <summary>
	/// 视图控制类
	/// </summary>
	/// <![CDATA[2014-8-7 17:52:59]]>
	public class View : DLL.ShowLayer.FormView
	{
		private Component clsthisComp;

		#region 添加、修改
		private TextBox tbPersonID = new TextBox();
		private TextBox tbPersonJobNumber = new TextBox();
		private TextBox tbPersonName = new TextBox();
		private TextBox tbPersonDepartmentName = new TextBox();
		private DropDownList ddlTraining = new DropDownList();
		private TextBox tbPersonIDCard = new TextBox();
		#endregion 添加、修改

		#region 查询
		/// <summary>
		/// 培训班开始日期
		/// </summary>
		private TextBox tbQueryStartDate = new TextBox();
		/// <summary>
		/// 培训班结束日期
		/// </summary>
		private TextBox tbQueryEndDate = new TextBox();
		/// <summary>
		/// 所有培训班
		/// </summary>
		private DropDownList ddlQueryTraining = new DropDownList();
		#endregion 查询

		#region 浏览

		#endregion 浏览

		#region 构造函数
		/// <summary>
		/// 视图类构造函数
		/// </summary>
		/// <![CDATA[2014-8-29 15:18:45]]>
		public View(System.Web.UI.Page page)
			: base(page)
		{
			clsthisComp = new Component(page);

			clsComp = clsthisComp;
			
			//listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("唯一码", "TextBox", tbPersonID, "string", "strPersonID"));
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("工号", "TextBox", tbPersonJobNumber, "string", "strJobNumber"));
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("姓名", "TextBox", tbPersonName, "string", "strPersonName"));
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("身份证", "TextBox", tbPersonIDCard, "string", "strIDCard"));
			//listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("单位代码", "TextBox", tbPersonDepartmentName, "string", "strPersonDepartment"));
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("培训班", "DropDownList", ddlTraining, "int", "nTrainingID"));

			tbQueryStartDate.AutoPostBack = true;
			tbQueryEndDate.AutoPostBack = true;
			listQuery.Add(new TonyNet4V1.Structs.TitleControlEntity("培训开始日期", "TextBox", tbQueryStartDate, "", ""));
			listQuery.Add(new TonyNet4V1.Structs.TitleControlEntity("培训结束日期", "TextBox", tbQueryEndDate, "", ""));
			listQuery.Add(new TonyNet4V1.Structs.TitleControlEntity("培训班", "DropDownList", ddlQueryTraining, "int", "nTrainingID"));
		}
		#endregion 构造函数

		#region 类型转换

		protected override TonyNet4V1.EntityBase GetEntity()
		{
			return new Entity();
		}

		protected override TonyNet4V1.QueryEntityBase GetQuery()
		{
			return new QueryEntity();
		}

		protected override TonyNet4V1.ComponentBase GetComponent()
		{
			return clsthisComp;
		}

		#endregion 类型转换

		public override void Init()
		{
			tbQueryStartDate.TextChanged += new EventHandler(tbQueryStartDate_TextChanged);
			tbQueryEndDate.TextChanged += new EventHandler(tbQueryEndDate_TextChanged);

			base.Init();

			clsControls.ShowMySelfBuildTraining(ddlTraining, nUserID);
			if (bQueryByUserID)
			{
				clsControls.ShowTrainingWithAllByUserID(ddlQueryTraining, nUserID);
			}
			else
			{
				clsControls.ShowAllTrainingWithAll(ddlQueryTraining);
			}
		}

		/// <summary>
		/// 培训开始日期查询文本框文本变更后事件处理函数
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		void tbQueryStartDate_TextChanged(object sender, EventArgs e)
		{
			Training.QueryEntity clsTrainingQuery = new Training.QueryEntity();

			if (tbQueryStartDate.Text != "")
			{
				clsTrainingQuery.strQueryStartDate = tbQueryStartDate.Text;
			}
			else
			{
				clsTrainingQuery.strQueryStartDate = clsTrainingQuery.strAll;
			}

			if (tbQueryEndDate.Text != "")
			{
				clsTrainingQuery.strQueryEndDate = tbQueryEndDate.Text;
			}
			else
			{
				clsTrainingQuery.strQueryEndDate = clsTrainingQuery.strAll;
			}

			clsControls.ShowTrainingWithAll(ddlQueryTraining, clsTrainingQuery);
		}

		/// <summary>
		/// 培训结束日期文本变更后事件处理函数
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		void tbQueryEndDate_TextChanged(object sender, EventArgs e)
		{
			Training.QueryEntity clsTrainingQuery = new Training.QueryEntity();

			if (tbQueryStartDate.Text != "")
			{
				clsTrainingQuery.strQueryStartDate = tbQueryStartDate.Text;
			}
			else
			{
				clsTrainingQuery.strQueryStartDate = clsTrainingQuery.strAll;
			}

			if (tbQueryEndDate.Text != "")
			{
				clsTrainingQuery.strQueryEndDate = tbQueryEndDate.Text;
			}
			else
			{
				clsTrainingQuery.strQueryEndDate = clsTrainingQuery.strAll;
			}

			clsControls.ShowTrainingWithAll(ddlQueryTraining, clsTrainingQuery);
		}

		/// <summary>
		/// 显示一个学员的学习情况
		/// </summary>
		/// <param name="gv"></param>
		public void ShowOnLearnerLearnInfo(GridView gv)
		{
			gv.DataSource = clsthisComp.QueryByLearnerUserID(nUserID);
			gv.DataKeyNames = new string[] { "ID" };
			gv.DataBind();
		}
	}
}
